package com.tiantang.shiro.helloworld.controller;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * 
 * @description：功能描述	登录控制器
 * @author： liujinkun
 * 创建时间： 2018年1月20日
 * @version：1.0
 * Copyright (c) 2018年 京东方科技集团股份有限公司
 */
@Controller
@RequestMapping("sysUser")
public class SysUserController {
	
	private static Logger logger=LoggerFactory.getLogger(SysUserController.class);
	
	@RequestMapping("/login")
	public String login(@RequestParam("username") String username,@RequestParam("password") String password){
		Subject currentUser=SecurityUtils.getSubject();
		if(!currentUser.isAuthenticated()){
			UsernamePasswordToken token=new UsernamePasswordToken(username,password);
			token.setRememberMe(true);
			try {
				currentUser.login(token);
			} catch (AuthenticationException e) {
				logger.info("认证失败",e);
			}
		}
		return "redirect:/index.html";
	}

}
